<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<h1>setTimeout实现电子时钟</h1>
<hr>

<input type="text" id="myclock" value="" readonly/>
<input type="button" value="停止" onclick="stopclock();"/>
<input type="button" value="开始" onclick="startclock();"/>
<script>

    let mytimer;

    function show() {
        let d = new Date();
        let myclock = d.toLocaleString();
        document.getElementById("myclock").value = myclock;
        mytimer = setTimeout("show()", 1000); //递归调用
    }

    function stopclock() {
        //停止一个定时器对象。
        clearTimeout(mytimer);
    }

    function startclock() {
        show();
    }

    function myclock() {
        show();
    }

    window.onload = myclock;
</script>
</body>
</html>